package logic

import (
	"context"
	"errors"
	"shop/cache"

	"shop/shopRpc/internal/svc"
	"shop/shopRpc/shopRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartClearLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartClearLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartClearLogic {
	return &CartClearLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartClearLogic) CartClear(in *shopRpc.CartClearRequest) (*shopRpc.CartClearResponse, error) {
	// todo: add your logic here and delete this line
	err := cache.CartClear(in.UserId)
	if err != nil {
		return nil, errors.New("清空购物车失败")
	}
	return &shopRpc.CartClearResponse{
		Success: true,
	}, nil
}
